﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration;

using LoomDataEmulator.Core;

namespace LoomDataEmulator.Service
{
    public partial class LoomDataEmulatorService : ServiceBase
    {
        private LoomDataServer _loomDataServer;

        public LoomDataEmulatorService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            FileWatcher.Path = ConfigurationManager.AppSettings["WatchFolder"].ToString();
            FileWatcher.Created += new System.IO.FileSystemEventHandler(FileWatcher_Created);
        }

        void FileWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            //TODO: validate 
            //_loomDataServer.ProcessInput();
        }

        protected override void OnStop()
        {
            if(FileWatcher != null)
                FileWatcher.Dispose();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            _loomDataServer.Update();
        }

    }
}
